//
//  WorkerCell.m
//  Btpin
//
//  Created by Vic on 2019/3/26.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "WorkerCell.h"

#define WorkerCellLblTag (200)

@interface WorkerCell ()
{
    WorkerBaseView *baseView;
    UIView *lineView;
}
@end

@implementation WorkerCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}
- (void)initUI {
    baseView = [[WorkerBaseView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 95*Scale)];
    [self.contentView addSubview:baseView];
    
//    CGFloat lblWidth = (WIDTH-60*Scale)*0.25;
//    for (NSInteger i = 0; i < 4; i++) {
//        UILabel *lbl = [UIToolsControl initLabelWithFrame:CGRectMake(15*Scale+(lblWidth+5*Scale)*i, EndY(baseView)+5*Scale, lblWidth, CompanyTagsHeight) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
//        lbl.textAlignment = NSTextAlignmentCenter;
//        lbl.layer.cornerRadius = 2*Scale;
//        lbl.layer.masksToBounds = YES;
//        lbl.layer.borderColor = THEMECOLOR_OF_TEXT_cccccc.CGColor;
//        lbl.layer.borderWidth = 0.5;
//        [self.contentView addSubview:lbl];
//        lbl.tag = WorkerCellLblTag+i;
//        lbl.hidden = YES;
//    }
    
    CGFloat width = (WIDTH - 30)/4;
    for (NSInteger i = 0; i < 4; i++) {
        UIButton *cerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        cerBtn.tag = 1000+i;
        cerBtn.frame = CGRectMake(15+width*i, baseView.bottom + 7, width, 12);
        [self.contentView addSubview:cerBtn];
        cerBtn.hidden = YES;
        cerBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [cerBtn setTitleColor:RGB(85, 85, 85) forState:UIControlStateNormal];
    }
    
    lineView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(baseView)+15*Scale+CompanyTagsHeight, WIDTH, 8*Scale) backgroundColor:THEMECOLOR_OF_GRAY];
    [self.contentView addSubview:lineView];
}
- (void)reloadData {
    [baseView reloadData];
    
    NSArray *arr = @[@"班车接送", @"五险一金", @"节日礼物"];
    for (NSInteger i = 0; i < arr.count; i++) {
        UILabel *lbl = (UILabel *)[self viewWithTag:WorkerCellLblTag+i];
        lbl.text = arr[i];
        lbl.hidden = NO;
    }
}
- (void)reloadDataModel:(WorkerModel *)model {
    [baseView reloadDataModel:model];
//    for (NSInteger i = 0; i < 4; i++) {
//        UILabel *lbl = (UILabel *)[self viewWithTag:WorkerCellLblTag+i];
//        lbl.hidden = YES;
//    }
//    for (NSInteger i = 0; i < MIN(model.tagsArray.count, 4); i++) {
//        UILabel *lbl = (UILabel *)[self viewWithTag:WorkerCellLblTag+i];
//        lbl.text = model.tagsArray[i];
//        lbl.hidden = NO;
//    }
    
    NSMutableArray *array = [NSMutableArray array];
    NSInteger realname = [model.auth_info[@"realname"] integerValue];
    if (realname == 1) {
        NSDictionary *dic = @{@"name":@"实名已认证",@"icon":@"renzehng-shiming"};
        [array addObject:dic];
    }
    NSInteger avatar = [model.auth_info[@"avatar"] integerValue];
    if (avatar == 1) {
//        NSDictionary *dic = @{@"name":@"头像已认证",@"icon":@"renzheng-touxiang"};
//        [array addObject:dic];
        if ([model.sex isEqualToString:@"2"]) {
            NSDictionary *dic = @{@"name":@"头像已认证", @"icon":@"renzheng_touxiang_nv"};
            [array addObject:dic];
        } else {
            NSDictionary *dic = @{@"name":@"头像已认证", @"icon":@"renzheng-touxiang"};
            [array addObject:dic];
        }
    }
    NSInteger education = [model.auth_info[@"education"] integerValue];
    if (education == 1) {
        NSDictionary *dic = @{@"name":@"学历已认证",@"icon":@"renzheng-xueli"};
        [array addObject:dic];
    }
    NSInteger work = [model.auth_info[@"work"] integerValue];
    if (work == 1) {
        NSDictionary *dic = @{@"name":@"职业已认证",@"icon":@"renzhneg-zhiye"};
        [array addObject:dic];
    }
    
    for (NSInteger i = 0; i < 4; i++) {
        UIButton *cerBtn = (UIButton *)[self viewWithTag:1000+i];
        if (i+ 1 > array.count) {
           cerBtn.hidden = YES;
        } else {
            cerBtn.hidden = NO;
            NSDictionary *dic = array[i];
            [cerBtn setTitle:dic[@"name"] forState:UIControlStateNormal];
            cerBtn.titleLabel.font = Font(Font_13);
            [cerBtn setImage:[UIImage imageNamed:dic[@"icon"]] forState:UIControlStateNormal];
            cerBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -3, 0, 0);
        }
    }
    
    
//    if (model.tagsArray.count) {
//        if (array.count) {
//            lineView.frame = CGRectMake(0, EndY(baseView)+15*Scale+CompanyTagsHeight+18, WIDTH, 8*Scale);
//        }else{
//           lineView.frame = CGRectMake(0, EndY(baseView)+15*Scale+CompanyTagsHeight, WIDTH, 8*Scale);
//        }
//
//    } else {
        if (array.count) {
           lineView.frame = CGRectMake(0, EndY(baseView)+5*Scale+25*Scale, WIDTH, 8*Scale);
        } else {
            lineView.frame = CGRectMake(0, EndY(baseView)+5*Scale, WIDTH, 8*Scale);
        }
//    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
